package com.dk.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dk.VO.TbOrderVO;
import com.dk.pojo.TbOrder;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface TbOrderMapper extends BaseMapper<TbOrder> {

    @Select("select DISTINCT * from tb_cars INNER JOIN tb_order on tb_order.car_id = tb_cars.id where tb_order.user_id=#{userId}")
    @Select("select DISTINCT * from tb_carss INNER JOIN tb_order on tb_order.car_id = tb_carss.id where tb_order.user_id=#{userId}")
    List<TbOrderVO> getOrdersByUserId(@Param("userId") Long userId);

    @Select("select DISTINCT * from tb_cars INNER JOIN tb_order on tb_order.car_id = tb_cars.id where tb_order.user_id=#{userId}")
    List<TbOrderVO> getSoldCars(@Param("userId") Long userId);

    @Update("update tb_order set trade_no = #{trade_no},payment_time = #{date} where order_num = #{out_trade_no}")
    void updateTradeNoAndPaymentTimeByOrderNum(@Param("out_trade_no") String out_trade_no, @Param("trade_no") String trade_no, Date date);

    @Update("update tb_order set status = #{s} where order_num = #{refundOrderNum}")
    void updateStatusByOrderNum(@Param("refundOrderNum") String refundOrderNum, @Param("s") String s);

    @Update("update tb_order set status = #{s} where trade_no = #{trade_no}")
    void updateStatusByTradeNo(@Param("trade_no") String trade_no, @Param("s") String s);

    @Select("select DISTINCT * from tb_order where order_num = #{out_trade_no}")
    TbOrder selectByOrderNum(String out_trade_no);
}
